import {createSlice } from '@reduxjs/toolkit'
const tableSlice=  createSlice({
    name: 'tab',
    initialState: {
        isCollapsed: false,
        tagsList:[
            {
                path: "/home",
                name: "home",
                label: "首页",
            },
        ]
    },
    reducers: {
        collapesChange(state) {
            state.isCollapsed = !state.isCollapsed;
        },
        addTag(state, action) {
         const {path,name,label}=action.payload
         const bool=state.tagsList.find((item)=>item.path===path)
         if(!bool){
            state.tagsList.push({ path, name, label });
         }
        },
        removeTag(state, action) {
            const { path } = action.payload;
            state.tagsList = state.tagsList.filter(tag => tag.path !== path);
        },
        clearTags(state) {
            state.tagsList = [];
        }
    }
})
export const { collapesChange, addTag,removeTag,clearTags} = tableSlice.actions;
export default tableSlice.reducer;